import api from '../../http/api'

export default {
    namespaced: true,
    state: {
        subjectsData: [],
        total: 0,
        totalPages: 0
    },
    getters: {},
    mutations: {
        SET_SUBJECTS(state, payload) {
            state.subjectsData = payload.rows;
            state.total = payload.total;
            state.totalPages = payload.pages;
        },
    },
    actions: {
        async getSubjectsAsync(context, pageSize, currentPage) {
            const { data } = await api.subjects.getSubjects(pageSize, currentPage);
            context.commit('SET_SUBJECTS', data.data);
            console.log(data.data.rows);
        },
        async addSubjectAsync(context, name) {
            const { data } = await api.subjects.addSubject(name);
            console.log(data);
            return data;
        },
        async updateSubjectAsync(context, subject) {
            console.log(context);
            const { data } = await api.subjects.updateSubject(subject);
            console.log(data);
            return data;
        },
        async delSubjectAsync(context, id) {
            const { data } = await api.subjects.delSubject(id);
            console.log(data);
            return data;
        },
    },
    modules: {}
}